﻿#include "frame_resource.h"

namespace ifire {

FrameResource::FrameResource(
    ID3D12Device* device, const FrameResourceDesc* desc) {
  HASSERT(device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
      IID_PPV_ARGS(CmdListAlloc.GetAddressOf())));
  // 这个不需要判断，至少应该有一个
  PassCB = std::make_unique<UploadBuffer<PassConstants>>(
      device, desc->PassCount, true);

  if (desc->MaterialCount > 0) {
    MaterialCB = std::make_unique<UploadBuffer<MaterialConstants>>(
        device, desc->MaterialCount, true);
    MaterialBuffer = std::make_unique<UploadBuffer<MaterialData>>(
        device, desc->MaterialCount, false);
  }

  if (desc->ObjectCount > 0) {
    ObjectCB = std::make_unique<UploadBuffer<ObjectConstants>>(
        device, desc->ObjectCount, true);
    ObjectCB_V2 = std::make_unique<UploadBuffer<ObjectConstantsV2>>(
        device, desc->ObjectCount, true);
    InstanceBuffer = std::make_unique<UploadBuffer<InstanceData>>(
        device, desc->ObjectCount, false);
  }

  if (desc->WaveVertexCount > 0) {
    WavesVB = std::make_unique<UploadBuffer<Vertex>>(
        device, desc->WaveVertexCount, false);
  }

  SsaoCB = std::make_unique<UploadBuffer<SsaoConstants>>(device, 1, true);

  if (desc->SkinnedObjectCount > 0) {
    SkinnedCB = std::make_unique<UploadBuffer<SkinnedConstants>>(
        device, desc->SkinnedObjectCount, true);
  }
}

FrameResource::~FrameResource() {}

} // namespace ifire
